﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.Web.Controls
{
    public enum ActionTypes
    {
        Link = 0,
        Button,
        Icon
    }

    [TypeConverter(typeof(ExpandableObjectConverter))]
    public abstract class ActionDetail
    {
        internal string Header { get; set; }
        internal ActionTypes Type { get; set; }
        public string Callback { get; set; }
        public string Class { get; set; }

        public ActionDetail()
        {
            this.Header = string.Empty;
        }

        public abstract string Render(string key);
    }

    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class ActionLink : ActionDetail
    {
        public string Text { get; set; }

        public ActionLink()
        {
            this.Type = ActionTypes.Link;
        }

        public override string Render(string key)
        {
            string retValue = string.Empty;

            //retValue = string.Format("<a href='#' class='{0}' onclick='{2}(\" + row.{3} + \")' style='cursor: pointer;'>{1}</a>", this.Class, this.Text, this.Callback, key);
            retValue = string.Format("<a href='#' class='{0}' style='cursor: pointer;'>{1}</a>", (!string.IsNullOrWhiteSpace(this.Class) ? this.Class : this.Callback), this.Text);

            return retValue;
        }
    }

    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class ActionButton : ActionDetail
    {
        public string Text { get; set; }

        public ActionButton()
        {
            this.Type = ActionTypes.Button;
        }

        public override string Render(string key)
        {
            string retValue = string.Empty;

            //retValue = string.Format("<button class='{0}' onclick='{2}(\" + row.{3} + \")' style='cursor: pointer;'>{1}</button>", this.Class, this.Text, this.Callback, key);
            retValue = string.Format("<button class='{0}' style='cursor: pointer;'>{1}</button>", (!string.IsNullOrWhiteSpace(this.Class) ? this.Class : this.Callback), this.Text);

            return retValue;
        }
    }

    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class ActionIcon : ActionDetail
    {
        public string Icon { get; set; }

        public ActionIcon()
        {
            this.Type = ActionTypes.Icon;
        }

        public override string Render(string key)
        {
            string retValue = string.Empty;

            //retValue = string.Format("<i class='{0} {1}' onclick='{2}(\" + row.{3} + \")' style='cursor: pointer;'></i>", this.Class, this.Icon, this.Callback, key);
            retValue = string.Format("<i class='{0} {1}' style='cursor: pointer;'></i>", (!string.IsNullOrWhiteSpace(this.Class) ? this.Class : this.Callback), this.Icon);
            
            return retValue;
        }
    }

}
